﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;

namespace TripleGameServices
{
    public class GameServices : ITripleGameServices
    {
        public int AddPlayer(PlayerDC playerDC)
        {
            return TripleGameDAL.AddPlayer(playerDC.playerName);
        }

        public void DeletePlayer(PlayerDC playerDC)
        {
            int playerId = int.Parse(playerDC.playerId);
            TripleGameDBEntities entity = new TripleGameDBEntities();
            TripleGameDAL.DeletePlayer(playerId, entity);
        }

        public int AddPendingGame(PlayerDC playerDC)
        {
            int playerId = int.Parse(playerDC.playerId);
            TripleGameDBEntities entity = new TripleGameDBEntities();
            return TripleGameDAL.AddPendingGame(playerId);
        }

        public IEnumerable<PendingGameDTO> GetAllPendingGames()
        {
            TripleGameDBEntities entity = new TripleGameDBEntities();
            List<PendingGameDTO> pendingGameDTOs = new List<PendingGameDTO>();
            foreach (var pendingGame in entity.PendingGames.Include("Player"))
            {
                PendingGameDTO pendingGameDTO = new PendingGameDTO();
                pendingGameDTO.pendingGameId = pendingGame.PendingGameId;
                pendingGameDTO.playerName = pendingGame.Player.Name;
                pendingGameDTOs.Add(pendingGameDTO);
            }

            return pendingGameDTOs;
        }
    }
}
